<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图形</title>
    <style type="text/css">
        *{
            text-align: center;
        }

    </style>
    <script>
        /*定义四个方法，其中三个是用于图形，还有一个用于输入错误后的循环*/
        var san = function () {
            var i = 1;
            while (i <= 10) {
                var j = 1;
                while (j <= i) {
                    document.write('*');
                    j++;
                }
                document.write('<br/>');
                i++;
            }

            /*for( i=1;i<=10;i++){
             for( j=1;j<=i;j++){
             document.write('*');
             }
             document.write('<br/>');
             }*/
        };
        var ju = function () {
            var i =1;
            while (i<=10){
                document.write('**********');
                document.write('<br/>');
                i++;
            }
            /*for (i = 1; i <= 10; i++) {
                document.write('**********');
                document.write('<br/>');
            }*/

        };
        var ling = function () {
            var i = 1;
            while (i <= 10) {
                var j = 1;
                while (j <= i) {
                    document.write('*');
                    j++;
                }
                document.write('<br/>');
                i++;
            }
            var i = 9;
            while (i >= 1) {
                var j = 1;
                while (j <= i) {
                    document.write('*');
                    j++;
                }
                document.write('<br/>');
                i--;
            }
            /*for (i = 1; i <= 10; i++) {
                for (j = 1; j <= i; j++) {
                    document.write('*');
                }
                document.write('<br/>');
            }
            for (i = 9; i >= 1; i--) {
                for (j = 1; j <= i; j++) {
                    document.write('*');
                }
                document.write('<br/>');
            }*/
        };

        var jieguo = function () {

            var num = prompt("请输入您想要的形状，a是三角形，b是矩形，c是菱形");
            switch (num){
                case 'a':
                    san();
                    break;
                case 'b':
                    ju();
                    break;
                case 'c':
                    ling();
                    break;
                default:
                    alert("您好，您的输入有误，请重新输入！");
                    jieguo();
            }

            /*if (num == 'a') {
                san();
            } else if (num == 'b') {
                ju();
            } else if (num == 'c') {
                ling();
            } else {
                alert("您好，您的输入有误，请重新输入！");
                jieguo();
            }*/
        };
        jieguo();
    </script>
</head>
<body>

</body>
</html>